// pages/record-list/record-list.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    title: '',
    showBack: true,
    type: '',
    records: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const { type, title } = options;
    wx.setNavigationBarTitle({
      title: title
    });
    
    this.setData({
      title,
      type
    });
    
    // 模拟获取记录数据
    this.loadRecords(type);
  },
  
  // 模拟加载记录数据
  loadRecords(type) {
    // 根据不同类型生成不同的模拟数据
    let records = [];
    const today = new Date();
    
    switch(type) {
      case 'diet': // 饮食
        records = [
          { id: 1, petName: '火火', content: '早餐 - 猫粮 50g', time: '2025-09-24 08:00', images: [] },
          { id: 2, petName: '火火', content: '午餐 - 猫罐头 100g', time: '2025-09-24 12:00', images: [] },
          { id: 3, petName: '火火', content: '晚餐 - 猫粮 80g', time: '2025-09-24 18:00', images: [] },
          { id: 4, petName: '火火', content: '零食 - 小鱼干 20g', time: '2025-09-23 15:30', images: [] }
        ];
        break;
      case 'water': // 喝水
        records = [
          { id: 1, petName: '火火', content: '早上喝水 - 100ml', time: '2025-09-24 08:30', images: [] },
          { id: 2, petName: '火火', content: '下午喝水 - 150ml', time: '2025-09-24 15:00', images: [] }
        ];
        break;
      case 'weight': // 体重
        records = [
          { id: 1, petName: '火火', content: '体重 - 2.5kg', time: '2025-09-24 09:00', images: [] },
          { id: 2, petName: '火火', content: '体重 - 2.45kg', time: '2025-09-17 09:00', images: [] }
        ];
        break;
      case 'grooming': // 洗护
        records = [
          { id: 1, petName: '火火', content: '洗澡 - 使用猫咪专用洗发水', time: '2025-09-20 19:00', images: [] },
          { id: 2, petName: '火火', content: '梳毛 - 全身梳理，去除死毛', time: '2025-09-22 18:30', images: [] },
          { id: 3, petName: '火火', content: '剪指甲 - 前爪后爪各5个', time: '2025-09-18 17:00', images: [] }
        ];
        break;
      case 'toilet': // 尿便
        records = [
          { id: 1, petName: '火火', content: '正常排便 - 成形', time: '2025-09-24 07:30', images: [] },
          { id: 2, petName: '火火', content: '正常排尿 - 清淡黄色', time: '2025-09-24 07:45', images: [] },
          { id: 3, petName: '火火', content: '正常排便 - 成形', time: '2025-09-24 19:15', images: [] },
          { id: 4, petName: '火火', content: '正常排尿 - 清淡黄色', time: '2025-09-24 19:30', images: [] }
        ];
        break;
      case 'memo': // 记事
        records = [
          { id: 1, petName: '火火', content: '火火今天特别活跃，玩了新买的玩具', time: '2025-09-24 20:00', images: [] },
          { id: 2, petName: '火火', content: '火火对新换的猫砂很适应', time: '2025-09-23 18:00', images: [] },
          { id: 3, petName: '火火', content: '火火最近喜欢趴在阳台上晒太阳', time: '2025-09-22 16:00', images: [] }
        ];
        break;
      case 'abnormal': // 异常
        records = [
          { id: 1, petName: '火火', content: '食欲不振 - 今天只吃了平时一半的猫粮', time: '2025-09-24 19:00', images: [] },
          { id: 2, petName: '火火', content: '打喷嚏 - 连续打了5个喷嚏', time: '2025-09-20 10:00', images: [] }
        ];
        break;
      case 'medicine': // 用药
        records = [
          { id: 1, petName: '火火', content: '驱虫药 - 体重2.5kg，用量1/4片', time: '2025-09-15 09:00', images: [] },
          { id: 2, petName: '火火', content: '维生素片 - 1片/天', time: '2025-09-20 08:30', images: [] }
        ];
        break;
      default:
        records = [];
    }
    
    this.setData({
      records
    });
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
  
  /**
   * 添加记录
   */
  addRecord() {
    // 跳转到添加记录页面
    wx.navigateTo({
      url: `/pages/addRecord/addRecord?type=${this.data.type}`
    });
  },
  
  /**
   * 添加记录到列表
   */
  addRecordToList(record) {
    // 为新记录生成ID
    const newRecord = {
      id: this.data.records.length > 0 ? Math.max(...this.data.records.map(item => item.id)) + 1 : 1,
      petName: record.petName,
      content: record.content,
      time: record.time,
      images: record.images
    };
    
    // 更新记录列表
    const records = [newRecord, ...this.data.records];
    this.setData({
      records: records
    });
    
    // 显示成功提示
    wx.showToast({
      title: '添加成功',
      icon: 'success'
    });
  }
})